#include "widget.h"
#include "ui_widget.h"

#include <QShortcut>
#include <QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->horizontalSlider->setMinimum(0);
    ui->horizontalSlider->setMaximum(100);
    ui->horizontalSlider->setSingleStep(10);
    ui->horizontalSlider->setValue(0);

    // -号快捷键
    QShortcut* sct1 = new QShortcut(this);
    sct1->setKey(QKeySequence("-"));
    connect(sct1, &QShortcut::activated, this, &Widget::subValue);

    QShortcut* sct2 = new QShortcut(this);
    sct2->setKey(QKeySequence("="));
    connect(sct2, &QShortcut::activated, this, &Widget::addValue);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_horizontalSlider_valueChanged(int value)
{
    ui->label->setText(QString::number(value));
}

void Widget::subValue()
{
    int value = ui->horizontalSlider->value();
    ui->horizontalSlider->setValue(value - 10);
}

void Widget::addValue()
{
    int value = ui->horizontalSlider->value();
    ui->horizontalSlider->setValue(value + 10);
}
